function kaoqinManage() {
    var _this = this;
    _this.userCount = 0;
    var page;
    _this.page_size1 = 10;
    _this.page_size2 = 10;

    // init
    _this.init = function(page_1) {
        page = page_1;
        _this.initTable_kaoqin();
        _this.initEvent();
    }

    // 考勤列表
    _this.initTable_kaoqin = function() {
        var list_url = appPath + "/admin/projectOffline/userKaoqinList";
        page.init("kaoqin_user_form", list_url, "kaoqin_user_list", "kaoqin_user_page", 1, _this.page_size1);
        page.goPage(1);
        page.list = function(dataList){
            _this.obj = dataList;
            if(dataList == null){
                return;
            }
            var len = dataList.length;
            _this.userCount = len;
            var inner = "", item;
            // 组装数据
            for(var i=0; i< len; i++) {
                item = dataList[i];
                // 组装数据
                inner += "<tr>";
                inner += '<td width="50"><input type=\"checkbox\" name="userBox" value="' + item['userId'] + '"></td>';
                if(item.signTime != ''){
                    var str = item.signTime;
                    inner += "<td>"+str.substring(0,16)+"</td>";
                }else{
                    inner += "<td>/</td>";
                }
                inner += "<td>"+item.userName+"</td>";
                inner += "<td>"+item.companyName+"</td>";
                if(item.departmentName == null || item.departmentName == ""){
                    inner += "<td>/</td>";
                }else{
                    inner += "<td>"+item.departmentName+"</td>";
                }
                inner += "<td>"+TimeUtil.getHouAndMinAndSec(item['studyTime'])+"</td>";
                if(1 == item.signType){
                    inner += "<td>扫码签到</td>";
                }else{
                    inner += "<td>管理员添加</td>";
                }
                inner += "</tr>";
            }
            return inner;
        }

    };


    _this.initEvent = function () {
        // 搜索（考勤）
        $("#kaoqin_user_search").click(function () {
            debugger
            var value = $('#click-kaoqin-type').find("span[class=active]").attr("data-value");
            if("1" == value){
                $(".nokaoqinTd").hide();
                $(".kaoqinTd").show();
                _this.initTable_kaoqin();
            }else if("2" == value){
                $(".nokaoqinTd").show();
                $(".kaoqinTd").hide();
                _this.initTable_Nokaoqin();
            }
        });


        // 全部（考勤）
        $("#kaoqin_user_all").click(function () {
            $("#kaoqin_user_name").val("");
            $("#kaoqin_company_name").val("");
            $("#signType").val("");

            var value = $('#click-kaoqin-type').find("span[class=active]").attr("data-value");
            if("1" == value){
                $(".nokaoqinTd").hide();
                $(".kaoqinTd").show();
                _this.initTable_kaoqin();
            }else if("2" == value){
                $(".nokaoqinTd").show();
                $(".kaoqinTd").hide();
                _this.initTable_Nokaoqin();
            }

        });


        // 全选
        $("#checkAll").click(function () {
            _this.userCheckAll();
        });

        $(".nokaoqinTd").hide();
        $(".kaoqinTd").show();
        $('#click-kaoqin-type').on("click", "span", function(){
            $('#click-kaoqin-type').find("span").removeClass("active");
            $(this).addClass("active");
            var value = $(this).attr("data-value");
            if("1" == value){
                $(".nokaoqinTd").hide();
                $(".kaoqinTd").show();
                _this.initTable_kaoqin();
            }else if("2" == value){
                $(".nokaoqinTd").show();
                $(".kaoqinTd").hide();
                _this.initTable_Nokaoqin();
            }
        });
    }

    // 导出考勤签到表
    _this.signExport=function(projectId){
        if(_this.userCount > 0){
            window.location.href = appPath + '/admin/projectOffline/signExport?projectId='+ projectId;
        }else{
            layer.msg('暂无可导出的数据', {icon: 7,  skin: 'layer-ext-moon'});
        }
    }



    // 全选
    _this.userCheckAll=function(){
        var flag=$("#checkAll").prop("checked");
        $('#kaoqin_user_list input[type="checkbox"]').prop("checked",flag);
    }

    // 选择人员
    _this.adminKaoqin = function () {
        _this.initTable_Nokaoqin();
    };


    // 未考勤考勤列表
    _this.initTable_Nokaoqin = function() {
        var list_url = appPath + "/admin/projectCenterTrain/userNoKaoqinList";
        page.init("kaoqin_user_form", list_url, "kaoqin_user_list", "kaoqin_user_page", 1, _this.page_size1);
        page.goPage(1);
        page.list = function(dataList){
            _this.obj = dataList;
            if(dataList == null){
                return;
            }
            var len = dataList.length;
            _this.userCount = len;
            var inner = "", item;
            // 组装数据
            for(var i=0; i< len; i++) {
                item = dataList[i];
                // 组装数据
                inner += "<tr>";
                inner += '<td width="50"><input type=\"checkbox\" name="userBox" value="' + item['user_id'] + '"></td>';
                inner += "<td>"+item.user_name+"</td>";
                inner += "<td>"+item.company_name+"</td>";
                if(item.department_name == null || item.department_name == "" || undefined == item.department_name ){
                    inner += "<td>/</td>";
                }else{
                    inner += "<td>"+item.department_name+"</td>";
                }

                inner += '<td><a href="javascript:kaoqinManage.kaoqin(\''+ item['user_id'] +'\');" class="a a-info">签到</a> </td>';
                inner += "</tr>";
            }
            return inner;
        }

    };

    // 扫码签到
    _this.scanSign = function () {
        // 扫码签到弹窗
        layer.open({
            type: 1,
            title: '扫码签到',
            shadeClose: true,
            shade: 0.1,
            area: ['310px', '345px'],
            content: '<img src="'+$("#codeUrl").val()+'">'
        });
    };
    // 单个签到
    _this.kaoqin = function (userId) {
        var userIds =[];
        userIds.push(userId);
        _this.sign(userIds.join(","))
    };
    // 批量签到
    _this.adminKaoqin = function(){
        var userIds=[];
        $('#kaoqin_user_list input:checked').each(function(i,e){
            userIds.push($(this).val());
        });
        if(userIds.length==0){
            layer.msg("未选择人员");return;
        }
        _this.sign(userIds.join(","))
    };


    // 扫码签到
    _this.sign = function (userIds) {
        layer.confirm("确定手动签到吗?", {
            icon : 3,
            btn : [ "确认", "取消" ]
        }, function() {
            // 扫码签到弹窗
            $.ajax({
                url: appPath + '/admin/projectCenterTrain/batchSign',
                async: false,
                type: 'post',
                data: {
                    'projectId': $("#projectId").val(),     // 项目id
                    'userIds': userIds
                },
                success: function (data) {
                    var code = data['code'];
                    if (code == 10000) {
                        layer.alert('操作成功', {icon: 1, skin: 'layer-ext-moon'}, function (index) {
                            layer.close(index);
                            // 刷新列表人员
                            _this.initTable_Nokaoqin();
                        });
                    } else {
                        layer.alert('操作失敗', {icon: 2, skin: 'layer-ext-moon'});
                    }
                }
            });
        })
    }
}

var kaoqinManage = new kaoqinManage();